package com.waar.kickball.model;

import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * @author Craig McIlwee
 * Copyright Lance + Craig 2013
 */
@Entity
@Table(name = "frame")
public class Frame extends KickballEntity {

	private boolean top;
	@OneToMany
	@JoinColumn(name = "frame_id")
	private Set<Player> fielders;
	@OneToMany(fetch = FetchType.EAGER)
	@JoinColumn(name = "frame_id")
	private Set<AtBat> atBats;
	
	Frame() { }
	
	/**
	 * @param top true for top, false for bottom
	 * @param fielders players that fielded
	 * @param atBats players that kicked
	 */
	public Frame(boolean top, Set<Player> fielders, Set<AtBat> atBats) {
		this.top = top;
		this.fielders = fielders;
		this.atBats = atBats;
	}
	
	/**
	 * @return true if top of the inning, false if bottom
	 */
	public boolean isTop() {
		return top;
	}
	
	/**
	 * Returned set is not modifiable.
	 * @return the players that fielded
	 */
	public Set<Player> getFielders() {
		return fielders;
	}
	
	/**
	 * Returned set is not modifiable.
	 * @return the players that kicked
	 */
	public Set<AtBat> getAtBats() {
		return atBats;
	}
	
}
